package com.chinacreator.galaxylive.exception;

import com.alibaba.fastjson.JSONException;
import com.chinacreator.c2.web.exception.Error;
import com.chinacreator.c2.web.exception.RestException;
import com.chinacreator.galaxylive.utils.ToolUtil;
import com.google.gson.JsonSyntaxException;
import org.springframework.http.ResponseEntity;

import javax.ws.rs.core.Response;

/**
 * 外部接口请求失败
 * Created by 敢超 on 2017/6/15.
 */
public class OutHttpRestException extends RestException{

    public OutHttpRestException(ResponseEntity response){
        super("外部接口请求失败，http错误编码："+response.getStatusCode().value()+",错误Body："+String.valueOf(response.getBody()),Response.Status.fromStatusCode(response.getStatusCode().value()));
        String o = (String)response.getBody();
        if(o != null){
            try{
                Error error = ToolUtil.jsonToObject(o,Error.class);
                this.setErrorNum(error.getErrorCode());
            }catch (Exception e){

            }

        }
    }
    public class Error {

        private String errorCode;
        private String errorMessage;

        public String getErrorCode() {
            return errorCode;
        }

        public void setErrorCode(String errorCode) {
            this.errorCode = errorCode;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }
    }


}
